/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxIndex;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CompactIndex
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   private static final String ACTION_START = "start";
/*     */   private static final String ACTION_STATUS = "status";
/*     */   private static final String STATUS_STARTED = "started";
/*     */   private static final String STATUS_RUNNING = "running";
/*     */   private static final String STATUS_IDLE = "idle";
/*  47 */   private static final String[] TARGET_ACCOUNT_PATH = { "mbox", "id" };
/*     */   
/*     */ 
/*     */ 
/*     */   protected String[] getProxiedAccountPath()
/*     */   {
/*  53 */     return TARGET_ACCOUNT_PATH;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  61 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  68 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  70 */     String action = request.getAttribute("action");
/*     */     
/*  72 */     Element mreq = request.getElement("mbox");
/*  73 */     String accountId = mreq.getAttribute("id");
/*     */     
/*  75 */     Provisioning prov = Provisioning.getInstance();
/*  76 */     Account account = prov.get(Key.AccountBy.id, accountId, zsc.getAuthToken());
/*  77 */     if (account == null) {
/*  78 */       throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
/*     */     }
/*     */     
/*  81 */     if (account.isCalendarResource())
/*     */     {
/*  83 */       CalendarResource resource = prov.get(Key.CalendarResourceBy.id, account.getId());
/*  84 */       checkCalendarResourceRight(zsc, resource, Rights.Admin.R_reindexCalendarResourceMailbox);
/*     */     } else {
/*  86 */       checkAccountRight(zsc, account, Rights.Admin.R_reindexMailbox);
/*     */     }
/*     */     
/*  89 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/*  90 */     if (mbox == null) {
/*  91 */       throw ServiceException.FAILURE("mailbox not found for account " + accountId, null);
/*     */     }
/*     */     
/*  94 */     Element response = zsc.createElement(AdminConstants.COMPACT_INDEX_RESPONSE);
/*  95 */     if ("start".equalsIgnoreCase(action)) {
/*  96 */       if (mbox.index.isCompactIndexInProgress()) {
/*  97 */         response.addAttribute("status", "running");
/*     */       } else {
/*  99 */         mbox.index.startCompactIndex();
/*     */       }
/* 101 */       response.addAttribute("status", "started");
/* 102 */     } else if ("status".equalsIgnoreCase(action)) {
/* 103 */       if (mbox.index.isCompactIndexInProgress()) {
/* 104 */         response.addAttribute("status", "running");
/*     */       } else {
/* 106 */         response.addAttribute("status", "idle");
/*     */       }
/*     */     } else {
/* 109 */       throw ServiceException.INVALID_REQUEST("Unknown action: " + action, null);
/*     */     }
/*     */     
/* 112 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 117 */     relatedRights.add(Rights.Admin.R_reindexMailbox);
/* 118 */     relatedRights.add(Rights.Admin.R_reindexCalendarResourceMailbox);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CompactIndex.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */